//
//  CPSCCategoryResultNavBarView.m
//  CollTest
//
//  Created by codew on 11/19/21.
//

#import "CPSCCategoryResultNavBarView.h"

@interface CPSCCategoryResultNavBarView ()

@property (nonatomic, strong) UIView * viewFieldSearchSuper;
@property (nonatomic, strong) UIView * viewLeftSuper;
@property (nonatomic, strong) UIView * viewRightSuper;
@property (nonatomic, strong) UITextField * textFieldSearch;
@end

@implementation CPSCCategoryResultNavBarView




- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]){
        
        [self initSubviews];
        [self makeContraints];
    }
    return self;
}


- (void)initSubviews
{
    
    [self addSubview:self.viewFieldSearchSuper];
    [self addSubview:self.viewLeftSuper];
    [self addSubview:self.viewRightSuper];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewLeftSuperAction)];
    [self.viewLeftSuper addGestureRecognizer:tap];
    
    UITapGestureRecognizer * tapSearch = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewFieldSearchSuperAction)];
    [self.viewFieldSearchSuper addGestureRecognizer:tapSearch];
    
    UITapGestureRecognizer * tapRight = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewRightSuperAction)];
    [self.viewRightSuper addGestureRecognizer:tapRight];
    
    
    [self deBugUI];
}


- (void)viewFieldSearchSuperAction
{
    NSLog(@"%s", __func__);
    if (self.blockSearch) {
        self.blockSearch();
    }
}

- (void)viewLeftSuperAction
{
    NSLog(@"%s", __func__);
    if (self.blockLeftBlock) {
        
        self.blockLeftBlock();
    }
}

- (void)viewRightSuperAction
{
    NSLog(@"%s", __func__);
    if (self.blockRight) {
        
        self.blockRight();
    }
}


- (void)makeContraints {
    
    CGFloat valueViewBottom = 10;
    CGFloat valueLeft = 52;
    CGFloat valueHeight = 34;
    CGFloat valueRightViewWidth = 46;
    
    
    [self.viewFieldSearchSuper mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(valueHeight);
        make.bottom.mas_equalTo(-valueViewBottom);
        make.right.mas_equalTo(-valueRightViewWidth);
        make.left.mas_equalTo(valueLeft);
    }];
    
    [self.viewLeftSuper mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(0);
        make.height.mas_equalTo(valueHeight);
        make.width.mas_equalTo(valueLeft);
        make.bottom.mas_equalTo(-valueViewBottom);
    }];

    [self.viewRightSuper mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(valueHeight);
        make.width.mas_equalTo(valueRightViewWidth);
        make.bottom.mas_equalTo(-valueViewBottom);
    }];
}

- (void)deBugUI
{
    //    self.viewHtmlContentSuper.backgroundColor = kCPSCRandomColor;
    //    self.lblContent.backgroundColor = kCPSCRandomColor;
//    self.viewRightSuper.backgroundColor = kCPSCRandomColor;
//    self.stringSearchKey = @"工商注册";
}

- (void)setStringSearchKey:(NSString *)stringSearchKey
{
    _stringSearchKey = stringSearchKey;
    self.textFieldSearch.text = stringSearchKey;
}
#pragma mark - Getter Setter
- (UIView *)viewFieldSearchSuper
{
    
    if (!_viewFieldSearchSuper) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        view.layer.cornerRadius = 6;
        view.layer.masksToBounds = YES;
        
        UIImageView * imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"category_search"];
        [view addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.height.width.mas_equalTo(16);
            make.centerY.equalTo(view.mas_centerY);
            make.left.mas_equalTo(12);
        }];
        
        
        UIView * viewTextFieldSuper = [[UIView alloc] init];
        [view addSubview:viewTextFieldSuper];
        [viewTextFieldSuper mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageView.mas_right).offset(10);
            make.right.mas_equalTo(0);
            make.top.bottom.mas_equalTo(0);
        }];

        UITextField * textField = [UITextField new];
        textField.font = [UIFont boldSystemFontOfSize:15];
        textField.placeholder = @"输入您想要搜索的内容";
        textField.keyboardType = UIKeyboardTypeNumberPad;
        [viewTextFieldSuper addSubview:textField];
        [textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_equalTo(0);
        }];
             
        textField.userInteractionEnabled = NO;
        _textFieldSearch = textField;
        
        _viewFieldSearchSuper = view;
    }
    return _viewFieldSearchSuper;
}

- (UIView *)viewLeftSuper
{
    
    if (!_viewLeftSuper) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor clearColor];
        view.clipsToBounds = YES;
                        
        UIImageView * imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"chips_nav_whiteBack"];
                
        [view addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(16.5);
            make.centerY.equalTo(view.mas_centerY);
            make.left.mas_equalTo(16);
        }];

        _viewLeftSuper = view;
    }
    return _viewLeftSuper;
}


- (UIView *)viewRightSuper
{
    
    if (!_viewRightSuper) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor clearColor];
        view.clipsToBounds = YES;
        
        // 24/20
        UIImageView * imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"category_nav_right"];
                
        [view addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(24);
            make.height.mas_equalTo(20);
            make.centerX.equalTo(view.mas_centerX);
            make.centerY.equalTo(view.mas_centerY).offset(-5);
            
        }];
        
        UILabel *lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor whiteColor];
        lblZy.font = [UIFont systemFontOfSize:9];
        lblZy.textAlignment = NSTextAlignmentCenter;
        lblZy.text = @"分类";
        [view addSubview:lblZy];
        [lblZy mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(imageView.mas_bottom).offset(2);
            make.left.right.mas_equalTo(0);
        }];
        
        _viewRightSuper = view;
    }
    return _viewRightSuper;
}


@end
